# -*- coding: utf-8 -*-
# author:jiangsibei

import os

import pytest
from tools.AdbOperation import *


# 获取工程路径
pro_path = os.path.dirname(inspect.getfile(inspect.currentframe())) + os.path.sep
configPath = os.path.join(pro_path, 'config.ini')

mode = Config.getRunparam(configPath,"mode")
apkurl =  Config.getRunparam(configPath,"apkurl")
reruns = Config.getRunparam(configPath,"reruns")
platform = Config.getRunparam(configPath,"platform")
buildNumber = Config.getRunparam(configPath,"buildNumber")
mark = Config.getRunparam(configPath,"mark")
reruns_delay = Config.getRunparam(configPath,"reruns_delay")



def Runcase(devices,reportpath,casepath,phone):

    adboperarion = AdbOperation()
    adboperarion.connect_device(devices)
    print("链接成功",os.getpid())
    if apkurl != "":
        AdbOperation.InstallApp()
    ReportPath = "reports/"+reportpath
    cmdopt_str = "--cmdopt="+str(phone)
    if mode == "2":
        while not casepath.empty():
            print("----",os.getpid())

            filename = pro_path + 'testcase/'+casepath.get()
            print("------------",filename)
            pytest.main(["-sv",cmdopt_str, '--alluredir', ReportPath,filename,'--reruns=5', '--reruns-delay=3'])
    elif mark != "":
        mark_param = "-m="+mark
        pytest.main(["-sv",cmdopt_str,mark_param, cmdopt_str,'--alluredir', ReportPath,'--reruns=5', '--reruns-delay=3',casepath])
    else:
        pytest.main(["-sv",cmdopt_str, '--alluredir', ReportPath,'--reruns=5', '--reruns-delay=3'])



#####该main函数方便调试单个文件
if __name__ == "__main__":
    adboperarion = AdbOperation()
    deviceslist =  adboperarion.getdevices()
    adboperarion = AdbOperation()
    adboperarion.connect_device(deviceslist[0])
    filename = pro_path + 'testcase/'+'test_complete_today_progress_L1_1.py'
    ReportPath = "reports/"+"1"
    #pytest.main(["-sv",'--alluredir', ReportPath,filename])
    pytest.main([ '--alluredir', ReportPath,filename,'--reruns=5', '--reruns-delay=3'])





